/*
Reorder 1st string based on 2nd string.
eg: (tractor,car)

output: carrtto or carrott or carrtot. The order of letters not in common doesn't matter.
*/

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>

using namespace std;

map<char, int> mp;

int comp(char l, char h)
{
    if (mp.count(l) && mp.count(h)) {
        return mp[l] <= mp[h];
    }
    return true;
}

int main(int argc, char **argv)
{
    mp['c'] = 0;
    mp['a'] = 1;
    mp['r'] = 2;
    string str = "carrtto";
    sort(str.begin(), str.end(), comp);
    cout << str << endl;
}
